package com.openbravo.pos.payment;

public class MagCardParserIntelligent
  implements MagCardParser
{
  private String m_sHolderName;
  private String m_sCardNumber;
  private String m_sExpirationDate;
  private StringBuffer m_sField;
  private static final int READING_HOLDER = 0;
  private static final int READING_NUMBER = 1;
  private static final int READING_DATE = 2;
  private static final int READING_FINISHED = 3;
  private int m_iAutomState;

  public MagCardParserIntelligent()
  {
    reset();
  }

  public void reset()
  {
    this.m_sHolderName = null;
    this.m_sCardNumber = null;
    this.m_sExpirationDate = null;
    this.m_sField = new StringBuffer();
    this.m_iAutomState = 0;
  }

  public void append(char paramChar)
  {
    switch (this.m_iAutomState)
    {
    case 0:
    case 3:
      if (paramChar == '\t')
      {
        this.m_sHolderName = this.m_sField.toString();
        this.m_sField = new StringBuffer();
        this.m_iAutomState = 1;
      }
      else if (paramChar == '\n')
      {
        this.m_sHolderName = null;
        this.m_sCardNumber = null;
        this.m_sExpirationDate = null;
        this.m_sField = new StringBuffer();
        this.m_iAutomState = 0;
      }
      else
      {
        this.m_sField.append(paramChar);
        this.m_iAutomState = 0;
      }
      break;
    case 1:
      if (paramChar == '\t')
      {
        this.m_sCardNumber = this.m_sField.toString();
        this.m_sField = new StringBuffer();
        this.m_iAutomState = 2;
      }
      else if (paramChar == '\n')
      {
        this.m_sHolderName = null;
        this.m_sCardNumber = null;
        this.m_sExpirationDate = null;
        this.m_sField = new StringBuffer();
        this.m_iAutomState = 0;
      }
      else
      {
        this.m_sField.append(paramChar);
      }
      break;
    case 2:
      if (paramChar == '\t')
      {
        this.m_sHolderName = this.m_sCardNumber;
        this.m_sCardNumber = this.m_sExpirationDate;
        this.m_sExpirationDate = null;
        this.m_sField = new StringBuffer();
      }
      else if (paramChar == '\n')
      {
        this.m_sExpirationDate = this.m_sField.toString();
        this.m_sField = new StringBuffer();
        this.m_iAutomState = 3;
      }
      else
      {
        this.m_sField.append(paramChar);
      }
    }
  }

  public boolean isComplete()
  {
    return this.m_iAutomState == 3;
  }

  public String getHolderName()
  {
    return this.m_sHolderName;
  }

  public String getCardNumber()
  {
    return this.m_sCardNumber;
  }

  public String getExpirationDate()
  {
    return this.m_sExpirationDate;
  }

  public String getTrack1()
  {
    return null;
  }

  public String getTrack2()
  {
    return null;
  }

  public String getTrack3()
  {
    return null;
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.MagCardParserIntelligent
 * JD-Core Version:    0.6.0
 */